﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ServiceModel;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;

namespace TM.QWeibo.SDK.Objects
{
    [DataContract]
    public class Tweet
    {
        /// <summary>
        /// 是否自已发的的微博枚举
        /// </summary>
        public enum ESelf
        {
            Yes=1,
            No=0
        }


        /// <summary>
        /// 是否是认证用户
        /// </summary>
        public enum EVip
        {
            Yes = 1,
            No = 0
        }

        /// <summary>
        /// 微博类型 1-原创发表、2-转载、3-私信 4-回复 5-空回 6-提及
        /// </summary>
        public enum ETweetType
        {
            /// <summary>
            /// 原创发表
            /// </summary>
            Original=1,
            /// <summary>
            /// 转载
            /// </summary>
            Forward,
            /// <summary>
            /// 私信
            /// </summary>
            Private,
            /// <summary>
            /// 回复
            /// </summary>
            Reply,
            /// <summary>
            /// 空回
            /// </summary>
            EmptyReply,
            /// <summary>
            /// 提及
            /// </summary>
            Mention
        }

        /// <summary>
        /// 原始内容
        /// </summary>
        [DataMember(Name = "origtext")]
        public string OrigtextEncode { get; set; }

        /// <summary>
        /// 原始内容反编码
        /// </summary>
        public string Origtext { 
            get {
                return HttpUtility.HtmlDecode(OrigtextEncode);
            }
        }
        /// <summary>
        /// 图片url列表
        /// </summary>
        [DataMember(Name = "image")]
        public List<string> ImageList { get; set; }

        /// <summary>
        /// 如果视频缩略图为空，则是第一张图片地址
        /// </summary>
        public string Image { 
            get
            {
                return (ImageList != null && ImageList.Count > 0) ? ImageList[0] : "";
            }
        }
        /// <summary>
        /// 微博被转次数
        /// </summary>
        [DataMember(Name = "count")]
        public long Count { get; set; }

        /// <summary>
        /// 点评次数
        /// </summary>
        [DataMember(Name = "mcount")]
        public long Mcount { get; set; }
        /// <summary>
        /// 来自
        /// </summary>
        [DataMember(Name = "from")]
        public string From { get; set; }
        /// <summary>
        /// 微博ID
        /// </summary>
        [DataMember(Name = "id")]
        public string Id { get; set; }
        /// <summary>
        /// 发表人帐户名
        /// </summary>
        [DataMember(Name = "name")]
        public string Name { get; set; }
        /// <summary>
        /// 发表人昵称
        /// </summary>
        [DataMember(Name = "nick")]
        public string NickName { get; set; }
        /// <summary>
        /// 是否自已发的的微博0：不是 1 是
        /// </summary>
        [DataMember(Name = "self")]
        public ESelf Self { get; set; }
        /// <summary>
        /// 时间戳
        /// </summary>
        [DataMember(Name = "timestamp")]
        public long Timestamp { get; set; }

        /// <summary>
        /// 人性化显示发表时间
        /// </summary>
        public string PublishTime{
            get {
                return Util.ConvertFromTimestamp(Timestamp);
            }
        }
        /// <summary>
        /// 当type=2 时，source 即为源微博
        /// </summary>
        [DataMember(Name = "source")]
        public Tweet Source { get; set; }

        /// <summary>
        /// 微博类型 1-原创发表、2-转载、3-私信 4-回复 5-空回 6-提及
        /// </summary>
        [DataMember(Name = "type")]
        public ETweetType Type { get; set; }
        /// <summary>
        /// 发表者头像url
        /// </summary>
        [DataMember(Name = "head")]
        public string Head { get; set; }

        /// <summary>
        /// 发表者所在地
        /// </summary>
        [DataMember(Name = "location")]
        public string Location { get; set; }
        /// <summary>
        /// 国家码
        /// </summary>
        [DataMember(Name = "country_code")]
        public string CountryCode { get; set; }
        /// <summary>
        /// 省份码
        /// </summary>
        [DataMember(Name = "province_code")]
        public string ProvinceCode { get; set; }
        /// <summary>
        /// 城市码
        /// </summary>
        [DataMember(Name = "city_code")]
        public string CityCode { get; set; }
        /// <summary>
        /// 是否微博认证用户
        /// </summary>
        [DataMember(Name = "isvip")]
        public long IsVip { get; set; }
        /// <summary>
        /// 发表者地理信息
        /// </summary>
        [DataMember(Name = "geo")]
        public string Geo { get; set; }
        /// <summary>
        /// 视频信息
        /// </summary>
        [DataMember(Name = "video")]
        public TweetVideo Video { get; set; }

        /// <summary>
        /// 包含的用户信息
        /// </summary>
        public List<SDK.Objects.UserInfo> Users { get; set; }

    }
    /// <summary>
    /// 微博视频
    /// </summary>
    [DataContract]
    public class TweetVideo {
        /// <summary>
        /// 缩略图地址
        /// </summary>
        [DataMember(Name = "picurl")]
        public string ThumbUrl { get; set; }
        /// <summary>
        /// 播放器地址
        /// </summary>
        [DataMember(Name = "player")]
        public string Player { get; set; }
        /// <summary>
        /// 视频原地址
        /// </summary>
        [DataMember(Name = "realurl")]
        public string RealUrl { get; set; }
        /// <summary>
        /// 视频的短url
        /// </summary>
        [DataMember(Name = "shorturl")]
        public string ShortUrl { get; set; }
        /// <summary>
        /// 视频标题
        /// </summary>
        [DataMember(Name = "title")]
        public string Title { get; set; }
    }
}
